package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter@Setter
public class Travel extends BaseDomain {

    public static final int STATE_REJECT=0;//拒绝状态
    public static final int STATE_NORMAL=1;//正常状态
    public static final int STATE_CHECKING=2;//审核状态
    public static final int STATE_RELEASE=3;//发布状态

    private String title;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone ="GMT+8" )
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;

    private String perExpends;//消费

    private Integer days;

    private Integer person;

    private User author;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone ="GMT+8" )
    private Date createTime;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone ="GMT+8" )
    private Date releaseTime;//发布时间

    private Boolean isPublic=true;//是否公开

    private Region place;

    private String coverUrl;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8" )
    private Date lastUpdateTime;

    private Integer state=STATE_NORMAL;//游记状态

    //浏览量
    private int browse = 1;

    //一对一关系
    private TravelContent travelContent;


    public String getStateDisplay(){
        if(state!=null){
            if(state==STATE_REJECT){
                return "拒绝";
            }else if(state==STATE_NORMAL){
                return "草稿";
            }else if(state==STATE_CHECKING){
                return "待审核";
            }else if(state==STATE_RELEASE){
                return "发布";
            }
        }
        return "";
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtils.toJSONString(map);
    }



}